package com.icinfo.cloud.provider.common.zzd.controller;

import cn.hutool.http.HttpStatus;
import com.icinfo.cloud.provider.common.zzd.dto.LoginResult;
import com.icinfo.cloud.provider.common.zzd.dto.ZzdUserInfo;
import com.icinfo.cloud.provider.common.zzd.service.IZzdUserLoginService;
import com.icinfo.cloud.provider.punish.dto.ZwdLoginRequest;
import com.icinfo.framework.common.web.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 描述：浙政钉登录前端控制器
 *
 * @Author zhengqiang
 * @Date 2022/12/6 16:05
 **/
@RestController
@RequestMapping("/app/zzd")
public class ZzdUserLoginController {
    @Resource
    private IZzdUserLoginService zzdUserLoginService;

    /**
     * 扫码登录
     *
     * @param authCode
     * @return
     */
    @GetMapping("/qrLogin")
    public Result<ZzdUserInfo> qrLogin(@RequestParam String authCode) {
        Result<ZzdUserInfo> zzdUserInfo = zzdUserLoginService.getZzdUserInfo(authCode);
        return zzdUserInfo;
    }

    /**
     * 一键登录
     *
     * @param zwdLoginRequest
     * @return
     */
    @PostMapping(value = "/login")
    public LoginResult Login(@RequestBody @Valid ZwdLoginRequest zwdLoginRequest) {
        LoginResult loginResult = new LoginResult();
        Result zwDingdingUser = zzdUserLoginService.zzdLogin(zwdLoginRequest);
        BeanUtils.copyProperties(zwDingdingUser, loginResult);
        loginResult.setMsg(zwDingdingUser.getMessage());
        if (HttpStatus.HTTP_OK == zwDingdingUser.getCode()) {
            loginResult.setStatus("success");
        } else {
            loginResult.setStatus("fail");
        }
        return loginResult;
    }


}
